<template>
  <div class="user">
      未开放敬请期待
  </div>
</template>
<script>
  import {
    PayList,
    editPay,
    PayAble,
    historyPayAble,
    BASEURL,
    addPay
  } from '@/api'
  export default {
    data() {
      return {
        options: [{
          value: '1',
          label: '未缴'
        }, {
          value: '2',
          label: '历史缴费'
        }],
        imageUrl: '',
        value: '1',
        PayList: [],
        enterpriseName:"",
        query: '',
        total: 0,
        pagesize: 10,
        pagenum: 1,
        addDialogFormVisible:false,
        addDialogFormVisible: false,
        addForm: {
          file1 :'',
          name:''
        },
        editDialogFormVisible: false,
        editForm: {
          enterpriseName: '',
          electricity: '',
          payableElectricity: '',
          water: '',
          payableWater: '',
          id: '',
        },
        grantDialogFormVisible: false,
        grantForm: {},
        roleList: [],
        roleId: '',
        // 添加用户的表单验证
        rules: {
          username: [{
            required: true,
            message: '请输入用户名',
            trigger: 'blur'
          }],
        }
      }
    },
    created() {
      this.initList()
    },
    computed: {
    },
    methods: {
      myClick(){
        console.log(123)
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.pagesize = val
        this.initList()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.pagenum = val
        this.initList()
      },
      Exportall(){
        window.open( `${BASEURL}lookup/details/excel/water/electricityAll`)
      },
      handleAvatarSuccess(res, file) {
        console.log(res)
        console.log(file)
        if (res.status === 0) {
                this.$message({
                  type: 'success',
                  message: '导入成功'
                })
                this.addDialogFormVisible = false
                this.initList()
                this.addForm.name = ""
              } else {
                this.$message({
                  type: 'warning',
                  message: res.meta.msg
                })
              }
              
        this.imageUrl = URL.createObjectURL(file.raw);
        // this.addForm.file1 = res.data.targetName
        console.log(this.addForm.file1)

        // console.log(this.addForm.targetName)
      },
      beforeAvatarUpload(file) {
        console.log(file)
        this.addForm.name  = file.name
        // const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;
        // if (!isJPG) {
        //   this.$message.error('上传头像图片只能是 JPG 格式!');
        // }
        if (!isLt2M) {
          this.$message.error('上传头像文件大小不能超过 2MB!');
        }
        return isLt2M;
      },
      initList() {
        console.log(this.value)
        if(this.value==2){
          console.log(123)
          this.loading = true
          historyPayAble({
            params: {
              enterpriseName:this.enterpriseName,
              page: this.pagenum-1,
              size : this.pagesize,
            }
          }).then(res => {
            console.log(res)
            
            this.PayList = res.data.content
            this.total = res.data.totalElements
            this.loading = false
          })
        }else{
          this.loading = true
          PayList({
            params: {
              enterpriseName:this.enterpriseName,
              page: this.pagenum-1,
              size : this.pagesize,
              sortField: 'update_time',
              sortType:'dsc'
            }
          }).then(res => {
            console.log(res.data.content)
            this.PayList = res.data.content
            this.total = res.data.totalElements
            this.loading = false
          })
        }
        
      },
      // 改变用户状态
      changeUserState(row) {
        console.log(row)
        changeUserState({
          uid: row.id,
          type: row.mg_state
        }).then(res => {
          if (res.meta.status === 200) {
            this.$message({
              type: 'success',
              message: '修改用户状态成功'
            })
          } else {
            this.$message({
              type: 'warning',
              message: res.meta.msg
            })
          }
        })
      },
      closeDiaglog(){
        this.$refs['addUserForm'].resetFields()
      },
      
      // 显示编辑用户对话框
      showEditDialog(row) {
        console.log(row)
        this.editDialogFormVisible = true
        
        // getUserById(row.id).then(res => {
        //   if (res.meta.status === 200) {
            this.editForm.enterpriseName = row.enterpriseName
            this.editForm.electricity = row.electricity
            this.editForm.payableElectricity = row.payableElectricity
            this.editForm.water = row.water
            this.editForm.payableWater = row.payableWater
            this.editForm.id= row.id
        //   }
        // })
      },
      // addUserSubmit(formName){
      //   this.$refs[formName].validate(valide => {
      //     if (valide) {
      //       console.log(this.addForm)
      //       addPay(this.addForm).then(res => {
      //         console.log(res)
      //         if (res.status === 0) {
      //           this.$message({
      //             type: 'success',
      //             message: '导入成功'
      //           })
      //           this.addDialogFormVisible = false
                
      //         } else {
      //           this.$message({
      //             type: 'warning',
      //             message: res.meta.msg
      //           })
      //         }
      //         this.initList()
      //       })
      //     }
      //   })
      // },
      // 编辑用户提交
      editUserSubmit(formName) {
        this.$refs[formName].validate(valide => {
          if (valide) {
            console.log(this.editForm)
            editPay(this.editForm).then(res => {
              console.log(res)
              if (res.status === 0) {
                this.$message({
                  type: 'success',
                  message: '编辑成功'
                })
                this.editDialogFormVisible = false
                this.initList()
              } else {
                this.$message({
                  type: 'warning',
                  message: res.meta.msg
                })
              }
            })
          }
        })
      },
      // 提交费用确认
      showGrantDialog(row) {
        console.log(row)
        this.$confirm('是否交完水电费?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 执行删除用户操作
          PayAble({
          params: {
            id:row.id,
            enterpriseInformationId: row.enterpriseInformationId
          }
        }).then(res => {
          console.log(res)
            if (res.status === 0) {
              this.$message({
                type: 'success',
                message: '缴费成功!'
              })
              this.initList()
            } else {
              this.$message({
                type: 'warning',
                message: res.meta.msg
              })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      // 显示分配角色对话框
      // showGrantDialog(row) {
      //   this.grantForm = row
      //   this.grantDialogFormVisible = true
      //   getRoleList().then(res => {
      //     console.log(res)
      //     if (res.meta.status === 200) {
      //       this.roleList = res.data
      //     }
      //   })
      // },
      // 分配角色
      // grantUserSubmit() {
      //   if (!this.roleId) {
      //     this.$message({
      //       type: 'warning',
      //       message: '角色不能为空，请选择！'
      //     })
      //   } else {
      //     grantUserRole({
      //       id: this.grantForm.id,
      //       rid: this.roleId
      //     }).then(res => {
      //       if (res.meta.status === 200) {
      //         this.$message({
      //           type: 'success',
      //           message: '设置角色成功'
      //         })
      //         this.grantDialogFormVisible = false
      //       } else {
      //         this.$message({
      //           type: 'error',
      //           message: res.meta.msg
      //         })
      //       }
      //     })
      //   }
      // }
    }
  }

</script>
<style lang="scss" scoped>
  .user {
    .margin-20 {
      margin: 20px 0;
    }

    .search-input {
      width: 250px;
    }

    .page {
      padding: 5px 0;
      background-color: #D3DCE6;
    }
  }

</style>
